Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
jsonrpc-lite
Advanced tools
Parse and Serialize JSON-RPC2 messages in node.js or browser.
Inspired by https://github.com/soggie/jsonrpc-serializer
A implementation of JSON-RPC 2.0 specifications
npm install jsonrpc-lite
const jsonrpc = require('jsonrpc-lite')
Creates a JSON-RPC 2.0 request object, return JsonRpc object.
id
: {String|Integer}method
: {String}params
: {Object|Array}, optionalconst requestObj = jsonrpc.request('123', 'update', {list: [1, 2, 3]})
// {
// jsonrpc: '2.0',
// id: '123',
// method: 'update',
// params: {list: [1, 2, 3]}
// }
Creates a JSON-RPC 2.0 notification object, return JsonRpc object.
method
: {String}params
: {Object|Array}, optionalconst notificationObj = jsonrpc.notification('update', {list: [1, 2, 3]})
// {
// jsonrpc: '2.0',
// method: 'update',
// params: {list: [1, 2, 3]}
// }
Creates a JSON-RPC 2.0 success response object, return JsonRpc object.
id
: {String|Integer}result
: {Mixed}const successObj = jsonrpc.success('123', 'OK')
// {
// jsonrpc: '2.0',
// id: '123',
// result: 'OK',
// }
Creates a JSON-RPC 2.0 error response object, return JsonRpc object.
id
: {String|Integer}error
: {JsonRpcError}const errorObj = jsonrpc.error('123', new jsonrpc.JsonRpcError('some error', 99))
// {
// jsonrpc: '2.0',
// id: '123',
// error: {code: 99, 'message': 'some error'},
// }
Takes a JSON-RPC 2.0 payload (string) and tries to parse it into a JSON. If successful, determine what object is it (response, notification, success, error, or invalid), and return it's type and properly formatted object.
message
: {String}return an array, or an object of this format:
single parsed request:
{
type: 'request',
payload: {
jsonrpc: '2.0',
id: 123,
method: 'update',
params: {}
}
}
batch parsed result:
[{
type: 'request',
payload: {
jsonrpc: '2.0',
id: '123',
method: 'update',
params: [1, 2, 3]
}
}, {
type: 'notification',
payload: {
jsonrpc: '2.0',
method: 'update',
params: {_id: 'xxx'}
}
}, {
type: 'success',
payload: {
jsonrpc: '2.0',
id: '123',
result: 'OK'
}
}, {
type: 'error',
payload: {
jsonrpc: '2.0',
id: '123',
error: [jsonrpc.JsonRpcError object]
}
}, {
type: 'invalid',
payload: [jsonrpc.JsonRpcError object]
}]
Takes a JSON-RPC 2.0 payload (Object) and tries to parse it into a JSON. If successful, determine what object is it (response, notification, success, error, or invalid), and return it's type and properly formatted object.
message
: {Object}return an JsonRpcParsed
object with type
and payload
.
Create a JsonRpcError instance.
message
: {String}code
: {Integer}data
: {Mixed} optionalconst error = new jsonrpc.JsonRpcError('some error', 999)
FAQs
Parse and Serialize JSON-RPC2 messages in node.js or browser.
The npm package jsonrpc-lite receives a total of 723,732 weekly downloads. As such, jsonrpc-lite popularity was classified as popular.
We found that jsonrpc-lite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.